/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.diplomka.webapp.messages;

import cz.muni.fi.diplomka.servicelayer.gamelogic.manager.MessageManager;
import cz.muni.fi.diplomka.servicelayer.gamelogic.managerimpl.MessageManagerImpl;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;

/**
 *
 * @author Jakub Kutil
 */
public class DeletePanel extends Panel {

    private MessageManager messageManager = new MessageManagerImpl();
    private Long messageId;
    private String type;
    private Long playerId;

    public DeletePanel(String id, PageParameters parameters) {
        super(id);

        if (parameters.containsKey("id")) {
            playerId = Long.valueOf(parameters.getString("id"));
        }
        if (parameters.containsKey("messageId")) {
            messageId = Long.valueOf(parameters.getString("messageId"));
        }
        if (parameters.containsKey("type")) {
            type = parameters.getString("type");
        }

        Form<?> form = new Form<Void>("form") {
            @Override
            protected void onSubmit() {

                messageManager.deleteMessage(messageId);
                PageParameters p = new PageParameters();
                p.add("id", playerId.toString());
                if (type.equals("recieved")) {
                    setResponsePage(MessageRecievedPage.class, p);
                } else{
                     setResponsePage(MessageSentPage.class, p);
                }
            }
        };

        add(form);
    }
}
